package com.m2bshop.shop.service.BankCardService;

import com.m2bshop.shop.dao.BankCardMapper;;
import com.m2bshop.shop.pojo.BankCard;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BankCardServiceImpl implements BankCardService{
    @Autowired
    BankCardMapper bankCardMapper;
    @Override
    public List<BankCard> getBankAllCard(int id) {
        return bankCardMapper.getAll(id);
    }

    @Override
    public String deleteBankCard(int id) {
        bankCardMapper.Delete(id);
        return "解绑成功";
    }

    @Override
    public String insertNewBankCard(BankCard bankCard) {
        bankCardMapper.Insert(bankCard);
        return "增加成功";
    }

    @Override
    public int UpdateBalance(int  bankid,int type,double number) {
        int info=0;
        BankCard bankCard= bankCardMapper.getById(bankid);
        if(type==0)//提现到银行卡，银行卡余额增加
        {
            bankCard.setBankBalance(bankCard.getBankBalance()+number);
        }
        else
        {
            if(bankCard.getBankBalance()-number<0)
            {
                info=0;
            }
            else {
                bankCard.setBankBalance(bankCard.getBankBalance()-number);
                info=1;
            }
        }
        bankCardMapper.Update(bankCard);
        return info;
    }
}
